package com.gbiac.modules.monitor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gbiac.modules.monitor.entity.SeatGroup;
import com.gbiac.modules.monitor.mapper.SeatGroupMapper;
import com.gbiac.modules.monitor.param.SeatGroupSaveParam;
import com.gbiac.modules.monitor.service.ISeatGroupService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 席位分组
 * @Author: jeecg-boot
 * @Date:   2024-11-30
 * @Version: V1.0
 */
@Service
public class SeatGroupServiceImpl extends ServiceImpl<SeatGroupMapper, SeatGroup> implements ISeatGroupService {

    @Override
    public void save(SeatGroupSaveParam param) {
        // 全部删除
        remove(new LambdaQueryWrapper<SeatGroup>().eq(SeatGroup::getGroupCode, param.getGroupCode()));
        List<String> seatIdList = param.getSeatIdList();
        if (CollectionUtils.isEmpty(seatIdList)) {
            return;
        }
        List<SeatGroup> seatGroupList = seatIdList.stream().map((seatId) -> {
            SeatGroup seatGroup = new SeatGroup();
            seatGroup.setGroupCode(param.getGroupCode());
            seatGroup.setGroupName(param.getGroupName());
            seatGroup.setClassType(param.getClassType());
            seatGroup.setOrgCode(param.getOrgCode());
            seatGroup.setSeatId(seatId);
            return seatGroup;
        }).collect(Collectors.toList());

        saveBatch(seatGroupList);
    }

    @Override
    public SeatGroup queryGroupBySeatId(String seatId) {
        return getBaseMapper().queryGroupBySeatId(seatId);
    }
}
